package com.ifreeee.practice.pc.bilibili;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Map;


/**
 * @author Administrator
 */
public class HttpUtil {

    /**
     * 初始重试次数
     */
    private static final Integer INIT_RE_TRY = 50;

    /**
     * 初始超时时间
     */
    private static final Integer INIT_TIMEOUT = 100;

    /**
     * 每次重试增加 超时时间
     */
    private static final Integer INCR_TIMEOUT = 100;

    /**
     * 等待页面异步加载
     */
    private static final WebClient webClient = new WebClient(BrowserVersion.CHROME);//新建一个模拟谷歌Chrome浏览器的浏览器客户端对象

    static {
        webClient.getOptions().setThrowExceptionOnScriptError(false);//当JS执行出错的时候是否抛出异常, 这里选择不需要
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);//当HTTP的状态非200时是否抛出异常, 这里选择不需要
        webClient.getOptions().setActiveXNative(false);//不启用ActiveX
        webClient.getOptions().setCssEnabled(false);//是否启用CSS, 因为不需要展现页面, 所以不需要启用
        webClient.getOptions().setJavaScriptEnabled(true); //很重要，启用JS
        webClient.getOptions().setDownloadImages(false);//不下载图片
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());//很重要，设置支持AJAX
    }

    /**
     * 使用Get方式获取数据
     *
     * @param url     URL包括参数，http://HOST/XX?XX=XX&XXX=XXX
     * @param charset
     * @return
     */
    public static String sendGet(String url, String charset) {
        String result = "";
        BufferedReader in = null;
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("cookie", "buvid3=85ACEFFD-4ACF-6987-8DF6-97C419CCECA728117infoc; _uuid=5BEB81089-6DF5-3106D-57B10-F9DFCE4466101028792infoc; buvid4=3AF4D9E4-5B1A-73BF-732C-6D4EEC6D284228754-022080622-wGk93k5ZDDjlXM0DfqSCTQ==; buvid_fp_plain=undefined; nostalgia_conf=-1; i-wanna-go-back=-1; b_ut=5; CURRENT_BLACKGAP=0; is-2022-channel=1; fingerprint3=64339accd671ee25a725a28533511e19; LIVE_BUVID=AUTO2816608895292007; b_timer={\"ffp\":{\"333.788.fp.risk_85ACEFFD\":\"182D4314855\",\"333.42.fp.risk_85ACEFFD\":\"182A9EBBEF1\",\"333.885.fp.risk_85ACEFFD\":\"182758986A2\",\"333.999.fp.risk_85ACEFFD\":\"182D4313DFF\",\"666.25.fp.risk_85ACEFFD\":\"182D43122E8\",\"333.1193.fp.risk_85ACEFFD\":\"182D4314258\",\"333.337.fp.risk_85ACEFFD\":\"182D0492E70\",\"333.1007.fp.risk_85ACEFFD\":\"182A995167E\",\"333.937.fp.risk_85ACEFFD\":\"182C3124766\",\"888.71455.fp.risk_85ACEFFD\":\"182A99703EB\",\"333.1073.fp.risk_85ACEFFD\":\"182C9C1C024\",\"888.2421.fp.risk_85ACEFFD\":\"182B4BAF719\",\"333.794.fp.risk_85ACEFFD\":\"182A9CF4F10\",\"777.5.0.0.fp.risk_85ACEFFD\":\"182B4BAF64F\",\"444.7.fp.risk_85ACEFFD\":\"182B4BAFA82\",\"444.55.fp.risk_85ACEFFD\":\"182C30BE3F0\",\"444.8.fp.risk_85ACEFFD\":\"182CA4C6B30\",\"333.880.fp.risk_85ACEFFD\":\"182D3BFBCBC\"}}; blackside_state=1; b_nut=100; rpdid=0zbfAHynYu|nGLMmyLP|4fE|3w1OW3wS; CURRENT_FNVAL=4048; fingerprint=9ffd034b386b141434c51bc7f0e30f54; DedeUserID=106592056; DedeUserID__ckMd5=61876c4c8cb27f76; bsource=search_baidu; hit-new-style-dyn=0; hit-dyn-v2=1; SESSDATA=48e538fb,1686222560,3c418*c2; bili_jct=174960b9e5f7bb434409f78dfd5c2660; sid=80u2rtgf; CURRENT_QUALITY=120; PVID=1; innersign=1; bp_video_offset_106592056=738304904128364700; b_lsid=882E77A4_18500CF168C; buvid_fp=9ffd034b386b141434c51bc7f0e30f54");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 建立实际的连接
            connection.connect();
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream(), charset));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("发送GET请求出现异常！" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }

    public static String sendGetDelay(String url, String charset, long delay) {
        if(delay > 0) {
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return sendGet(url, charset);
    }

    /**
         * POST请求，字符串形式数据
         *
         * @param url     请求地址
         * @param param   请求数据
         * @param charset 编码方式
         */
    public static String sendPostUrl(String url, String param, String charset) {

        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            URLConnection conn = realUrl.openConnection();
            // 设置通用的请求属性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 获取URLConnection对象对应的输出流
            out = new PrintWriter(conn.getOutputStream());
            // 发送请求参数
            out.print(param);
            // flush输出流的缓冲
            out.flush();
            // 定义BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
                    conn.getInputStream(), charset));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            //System.out.println("发送 POST 请求出现异常！" + e);
            e.printStackTrace();


        }
        // 使用finally块来关闭输出流、输入流
        finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return result;
    }

    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url   发送请求的 URL
     * @param param 请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
     * @return 所代表远程资源的响应结果
     */
    public static String sendPost(String url, String param) {
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            URLConnection conn = realUrl.openConnection();
            // 设置通用的请求属性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 获取URLConnection对象对应的输出流
            out = new PrintWriter(conn.getOutputStream());
            // 发送请求参数
            out.print(param);
            // flush输出流的缓冲
            out.flush();
            // 定义BufferedReader输入流来读取URL的响应
            in = new BufferedReader(
                    new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("发送 POST 请求出现异常！" + e);
            e.printStackTrace();
        }
        //使用finally块来关闭输出流、输入流
        finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return result;
    }

    /**
     * POST请求，Map形式数据
     *
     * @param url     请求地址
     * @param param   请求数据
     * @param charset 编码方式
     */
    public static String sendPost(String url, Map<String, String> param,
                                  String charset) {

        StringBuffer buffer = new StringBuffer();
        if (param != null && !param.isEmpty()) {
            for (Map.Entry<String, String> entry : param.entrySet()) {
                buffer.append(entry.getKey()).append("=")
                        .append(URLEncoder.encode(entry.getValue()))
                        .append("&");

            }
        }
        buffer.deleteCharAt(buffer.length() - 1);

        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            URLConnection conn = realUrl.openConnection();
            // 设置通用的请求属性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 获取URLConnection对象对应的输出流
            out = new PrintWriter(conn.getOutputStream());
            // 发送请求参数
            out.print(buffer);
            // flush输出流的缓冲
            out.flush();
            // 定义BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
                    conn.getInputStream(), charset));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("发送 POST 请求出现异常！" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输出流、输入流
        finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return result;
    }

    /**
     * 使用Get方式获取数据
     * 可以加载 需要 页面异步获取的数据
     *
     * @param url URL包括参数，http://HOST/XX?XX=XX&XXX=XXX
     * @return
     */
    public static String sendGetAsync(String url, long timeout) {
        String resStr = "";
        HtmlPage page = null;
        try {
            page = webClient.getPage(url);//尝试加载上面图片例子给出的网页
            webClient.waitForBackgroundJavaScript(timeout);//异步JS执行需要耗时,所以这里线程要阻塞30秒,等待异步JS执行结束
            if (page == null) {
                return resStr;
            }
            resStr = page.asXml();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            webClient.close();
        }
        return resStr;//直接将加载完成的页面转换成xml格式的字符串
    }

    public static void main(String[] args) {
        ////String httpUrl=jsionStr.replace(" ","");
        //String httpUrl = "{\"body\":{\"list\":[{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"01:20\",\"takeofftm\":\"02:30\",\"arraytm\":\"04:55\",\"volume\":\"14000\",\"isend\":\"是\"},{\"conveyancename\":\"O36869\",\"destzone\":\"510\",\"endtm\":\"02:50\",\"takeofftm\":\"03:30\",\"arraytm\":\"05:25\",\"volume\":\"28000\",\"isend\":\"否\"},{\"conveyancename\":\"O36869\",\"destzone\":\"510X\",\"endtm\":\"02:50\",\"takeofftm\":\"03:30\",\"arraytm\":\"05:25\",\"volume\":\"28000\",\"isend\":\"否\"},{\"conveyancename\":\"O36888\",\"destzone\":\"571\",\"endtm\":\"02:40\",\"takeofftm\":\"03:35\",\"arraytm\":\"05:10\",\"volume\":\"28000\",\"isend\":\"否\"},{\"conveyancename\":\"O36861\",\"destzone\":\"574\",\"endtm\":\"02:40\",\"takeofftm\":\"03:55\",\"arraytm\":\"05:35\",\"volume\":\"14000\",\"isend\":\"否\"},{\"conveyancename\":\"O36861\",\"destzone\":\"574R\",\"endtm\":\"02:40\",\"takeofftm\":\"03:55\",\"arraytm\":\"05:35\",\"volume\":\"14000\",\"isend\":\"否\"},{\"conveyancename\":\"O36861\",\"destzone\":\"574W\",\"endtm\":\"02:40\",\"takeofftm\":\"03:55\",\"arraytm\":\"05:35\",\"volume\":\"14000\",\"isend\":\"否\"},{\"conveyancename\":\"DZ6216\",\"destzone\":\"010\",\"endtm\":\"05:25\",\"takeofftm\":\"06:55\",\"arraytm\":\"09:55\",\"volume\":\"14000\",\"isend\":\"否\"},{\"conveyancename\":\"O36867\",\"destzone\":\"510\",\"endtm\":\"20:50\",\"takeofftm\":\"21:40\",\"arraytm\":\"23:35\",\"volume\":\"28000\",\"isend\":\"否\"},{\"conveyancename\":\"O36853\",\"destzone\":\"021\",\"endtm\":\"22:00\",\"takeofftm\":\"23:00\",\"arraytm\":\"00:55\",\"volume\":\"28000\",\"isend\":\"否\"},{\"conveyancename\":\"O36896\",\"destzone\":\"571\",\"endtm\":\"22:40\",\"takeofftm\":\"23:40\",\"arraytm\":\"01:15\",\"volume\":\"28000\",\"isend\":\"否\"},{\"conveyancename\":\"O36880\",\"destzone\":\"577\",\"endtm\":\"22:20\",\"takeofftm\":\"23:50\",\"arraytm\":\"01:15\",\"volume\":\"16000\",\"isend\":\"否\"},{\"conveyancename\":\"O36861\",\"destzone\":\"571R\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"O36869\",\"destzone\":\"021WF\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"O36869\",\"destzone\":\"512W\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"O36869\",\"destzone\":\"025WA\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"O36888-O36858\",\"destzone\":\"536X\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"},{\"conveyancename\":\"Y87971\",\"destzone\":\"021WG\",\"endtm\":\"\",\"takeofftm\":\"\",\"arraytm\":\"\",\"volume\":\"\",\"isend\":\"否\"}]},\"head\":{\"template\":\"2\",\"id\":\"1\",\"ip\":\"10.108.83.180\"}}";
        ////httpUrl=ledserviceIp+"af中国";
        //System.out.println("jsion===" + httpUrl);
        //String jsionResult = HttpUtil.sendPost("http://127.0.0.1:8081/ws/servlet", "jsonstr=" + httpUrl);

        String s = sendZhiChaoGet(null, null);
        System.out.println(s);
    }

    /**
     * 使用Get方式获取数据
     *
     * @param url     URL包括参数，http://HOST/XX?XX=XX&XXX=XXX
     * @param charset
     * @return
     */
    public static String sendZhiChaoGet(String url, String charset) {
        url = "https://mp.weixin.qq.com/s?__biz=Mzg5MTE0OTgxMA==&mid=2247484335&idx=7&sn=f72f696c8da6fafd1327ae6c93694598&chksm=cfd08f32f8a7062499fcb8d317f0651b3b4f980cad3198551fefa4f15e3858e13f5ce39aa7a2&scene=21#wechat_redirect";
        //url = "https://mp.weixin.qq.com/s?__biz=MjM5MDg5MDY5OQ==&mid=2247503374&idx=2&sn=01ad55b40c11096e14a0396346e7dfa0&chksm=a6bf61aa91c8e8bc0dfecd0965a30b2afd93c31172e24d8666965d6d9d1bd777b2c27a3434d6&scene=21#wechat_redirect";
        if (charset == null) {
            charset = "utf-8";
        }
        String result = "";
        BufferedReader in = null;
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            // 设置通用的请求属性
            //:authority: mp.weixin.qq.com
            //:method: GET
            //TODO :path: /s?__biz=Mzg5MTE0OTgxMA==&mid=2247483874&idx=2&sn=a6b08459c7fb1d8f63e5bac5af9cd57c&chksm=cfd08d7ff8a7046932d805203157afe695f28b32998b9dff46d611bf6b458b3698c81bb050c2&scene=21
            //:scheme: https

            //connection.setRequestProperty("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            connection.setRequestProperty("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            //connection.setRequestProperty("accept-encoding", "gzip, deflate, br");
            //connection.setRequestProperty("accept-language", "zh-CN,zh;q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6");
            //connection.setRequestProperty("cache-control", "max-age=0");
            //connection.setRequestProperty("cookie", "_qpsvr_localtk=0.5293579441849616; RK=WW+5i2exaP; ptcz=419d293bf7c22db951cae1e4aa53a9353d0c5811a39b3b70a36982191f511cb5; pgv_pvid=1463959878; fqm_pvqid=b61acbd4-042a-4fff-b62f-268148676cfa; fqm_sessionid=22bafde8-e606-46bb-b45b-e34b9d8d44cc; pgv_info=ssid=s5847927561; qqmusic_uin=0099587254; qqmusic_fromtag=6; rv2=802E252BC6FC4E262503999ECEE47D3A09ADC7597AA99F0613; property20=53FCD01B44109DBC8DED18909125CE61A941C720F966FB28EB469E88D77E6FD38173E5CA209C9D94; tvfe_boss_uuid=d39402f371bb0c3d; vversion_name=8.2.95; video_omgid=841d2345eeb0bc0c; pac_uid=0_a13458d0c3363; qqmusic_key=@GBZ0SzX2q; ETCI=1291211b76ac43bc94f5ecaee70273f9; g_f=3000006; channelIDMap=%7B%22cn1%22%3A%22200001760%22%2C%22cn2%22%3A%22200001761%22%2C%22cn3%22%3A%22200001762%22%2C%22cn4%22%3A%22200001763%22%2C%22cn5%22%3A%22200001764%22%2C%22cn6%22%3A%22200001783%22%2C%22cn7%22%3A%22200001784%22%2C%22cn8%22%3A%22200001785%22%2C%22cn9%22%3A%22200001786%22%2C%22cn10%22%3A%22200001787%22%2C%22cn11%22%3A%22200001788%22%2C%22cn12%22%3A%22200001780%22%2C%22cn13%22%3A%22200001790%22%2C%22cn14%22%3A%22200001798%22%2C%22cn15%22%3A%22200001809%22%2C%22cn16%22%3A%22200001813%22%2C%22cn17%22%3A%22200001816%22%2C%22cn18%22%3A%22200001819%22%2C%22cn19%22%3A%22200001822%22%2C%22cn20%22%3A%22200001831%22%2C%22cn21%22%3A%22200001832%22%2C%22cn22%22%3A%22200001836%22%2C%22cn23%22%3A%22200001783%22%2C%22cn24%22%3A%22200001783%22%2C%22cn25%22%3A%22200001783%22%2C%22cn26%22%3A%22200001761%22%2C%22cn27%22%3A%22200001761%22%2C%22cn28%22%3A%22200001761%22%2C%22cn29%22%3A%22200001953%22%7D; ldhbRecord=-1; logTrackKey=93d9547ac6484d2f89302ad24bf03da8; fuid=36ca83b327044a419d103a48f9a6806a; ywguid=854064034792; ywkey=ywWNArKAb1hq; rewardsn=; wxtokenkey=777; wwapp.vid=; wwapp.cst=; wwapp.deviceid=; skey=@L1D08fRtX; uin=o99587254");
            connection.setRequestProperty("cookie", "cookie: _qpsvr_localtk=0.5293579441849616; RK=WW+5i2exaP; ptcz=419d293bf7c22db951cae1e4aa53a9353d0c5811a39b3b70a36982191f511cb5; pgv_pvid=1463959878; fqm_pvqid=b61acbd4-042a-4fff-b62f-268148676cfa; fqm_sessionid=22bafde8-e606-46bb-b45b-e34b9d8d44cc; pgv_info=ssid=s5847927561; qqmusic_uin=0099587254; qqmusic_fromtag=6; rv2=802E252BC6FC4E262503999ECEE47D3A09ADC7597AA99F0613; property20=53FCD01B44109DBC8DED18909125CE61A941C720F966FB28EB469E88D77E6FD38173E5CA209C9D94; tvfe_boss_uuid=d39402f371bb0c3d; vversion_name=8.2.95; video_omgid=841d2345eeb0bc0c; pac_uid=0_a13458d0c3363; qqmusic_key=@GBZ0SzX2q; ETCI=1291211b76ac43bc94f5ecaee70273f9; g_f=3000006; channelIDMap=%7B%22cn1%22%3A%22200001760%22%2C%22cn2%22%3A%22200001761%22%2C%22cn3%22%3A%22200001762%22%2C%22cn4%22%3A%22200001763%22%2C%22cn5%22%3A%22200001764%22%2C%22cn6%22%3A%22200001783%22%2C%22cn7%22%3A%22200001784%22%2C%22cn8%22%3A%22200001785%22%2C%22cn9%22%3A%22200001786%22%2C%22cn10%22%3A%22200001787%22%2C%22cn11%22%3A%22200001788%22%2C%22cn12%22%3A%22200001780%22%2C%22cn13%22%3A%22200001790%22%2C%22cn14%22%3A%22200001798%22%2C%22cn15%22%3A%22200001809%22%2C%22cn16%22%3A%22200001813%22%2C%22cn17%22%3A%22200001816%22%2C%22cn18%22%3A%22200001819%22%2C%22cn19%22%3A%22200001822%22%2C%22cn20%22%3A%22200001831%22%2C%22cn21%22%3A%22200001832%22%2C%22cn22%22%3A%22200001836%22%2C%22cn23%22%3A%22200001783%22%2C%22cn24%22%3A%22200001783%22%2C%22cn25%22%3A%22200001783%22%2C%22cn26%22%3A%22200001761%22%2C%22cn27%22%3A%22200001761%22%2C%22cn28%22%3A%22200001761%22%2C%22cn29%22%3A%22200001953%22%7D; ldhbRecord=-1; logTrackKey=93d9547ac6484d2f89302ad24bf03da8; fuid=36ca83b327044a419d103a48f9a6806a; ywguid=854064034792; ywkey=ywWNArKAb1hq; rewardsn=; wxtokenkey=777; wwapp.vid=; wwapp.cst=; wwapp.deviceid=; skey=@L1D08fRtX; uin=o99587254");
            connection.setRequestProperty("if-modified-since", "Sun, 27 Nov 2022 03:33:47 +0800");
            //connection.setRequestProperty("sec-ch-ua", "Chromium\";v=\"104\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"104");
            //connection.setRequestProperty("sec-ch-ua-mobile", "?0");
            //connection.setRequestProperty("sec-ch-ua-platform", "Windows");
            //connection.setRequestProperty("sec-fetch-dest", "document");
            //connection.setRequestProperty("sec-fetch-mode", "navigate");
            //connection.setRequestProperty("sec-fetch-site", "none");
            connection.setRequestProperty("sec-fetch-user", "?1");
            connection.setRequestProperty("upgrade-insecure-requests", "1");
            //connection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36");

            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 建立实际的连接
            connection.connect();
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream(), charset));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("发送GET请求出现异常！" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }

}